import {addAtl, selByInit} from '../../../network/per/inter'
// import { UploadFile } from 'element-plus'
// import { UploadInstance } from 'element-plus'
// import {$ref} from "vue/macros";



export default {
    name: "AddPerInf",
    components: {},
    props: {},
    data() {
        return {
            token: "",
            // 回显
            menu:{
                imgUrl:null,
                imgUrlBase64:null
            },
            formData: {
                name: "",
                sex: 1,
                personalPhoto: "",
                highestEducation: 1,
                academicDegree: 1,
                idCard: "",
                graduationInstitutions: "",
                major: "",
                domicilePlace: "",
                politics: 1,
                nation: 1,
                nativePlace: "",
                graduationDate: null,
                brith: null,
                height: "",
                health: "",
                contactPhone: "",
                email: "",
                hobbies: "",
                computerApplicationAbility: "",
                computerGradeCertificate: "",
                wedlock: 1,
                selfEvaluation: "",
                remark: "",
            },
            'ResumeFillingTable': 'tab1',
            personalPhotoFileList: [],
            personalPhotoUploadHeaders: {},
            personalPhotoUploadData: {},
            // 教育经验
            edexTable:[],
            num : 0,
            //  工作经验
            saexTable:[],
            saexNUm:0,
            //  简历分类
            reclTable: {
                source: 1,
                type: 1,
                positionId:"",
                positionName:"",
                jobDemandId:""
            },
            // 非空检查
            rules: {
                source: [{
                    required: true,
                    message: '字段值不可为空',
                }],
                type: [{
                    required: true,
                    message: '字段值不可为空',
                }],
                positionId: [{
                    required: true,
                    message: '字段值不可为空',
                }],
                name: [
                    {
                        required: true,
                        message: '字段值不可为空',
                    }],
                sex: [
                    {
                        required: true,
                        message: '字段值不可为空',
                    }],
                idCard: [{
                    required: true,
                    message: '字段值不可为空',
                }],
                contactPhone: [{
                    required: true,
                    message: '字段值不可为空',
                }],
            },
            // 下拉框
            politicsOptions: [
                {
                    "label": "无党派人士",
                    "value": 1
                }, {
                    "label": "中共党员",
                    "value": 2
                }, {
                    "label": "群众",
                    "value": 3
                }
            ],
            nationOptions: [
                {
                    "label": "汉族",
                    "value": 1
                }, {
                    "label": "回族",
                    "value": 2
                }, {
                    "label": "维吾尔族",
                    "value": 3
                }
            ],
            wedlockOptions: [
                {
                    "label": "未婚",
                    "value": 1
                }, {
                    "label": "已婚",
                    "value": 2
                }, {
                    "label": "礼仪带梁洼",
                    "value": 3
                }
            ],
            sourceOptions: [
                {
                    "label": "51job",
                    "value": 1
                }, {
                    "label": "智联招聘",
                    "value": 2
                }, {
                    "label": "猎聘网",
                    "value": 3
                }, {
                    "value": 4,
                    "label": "BOSS直聘"
                }, {
                    "value": 5,
                    "label": "内推"
                }
            ],
            typeOptions: [
                {
                    "label": "  ",
                    "value": 1
                }, {
                    "label": "主动提交",
                    "value": 2
                }, {
                    "label": "制动搜索",
                    "value": 3
                }
            ],
            sexOptions: [
                {
                    "label": "男",
                    "value": 1
                }, {
                    "label": "女",
                    "value": 2
                }
            ],
            highestEducationOptions:[
                {
                    "label": "研究生",
                    "value": 1
                }, {
                    "label": "本科",
                    "value": 2
                }, {
                    "label": "专科",
                    "value": 3
                }
            ],
            academicDegreeOptions: [
                {
                    "label": "硕士",
                    "value": 1
                }, {
                    "label": "博士",
                    "value": 2
                }
            ],
            // 岗位选择
            ypgwOptions: [],
            dialogTableVisible:false,
            dialogImageUrlShow : false
        }
    },
    computed: {
        config(){
            return { token: this.token };
        }
    },
    watch: {},
    created() {
        this.formData.sex = this.sexOptions[0].value
    },
    mounted() {
        this.token = window.sessionStorage.getItem("tokenStr");
        selByInit().then((das=>{
            console.log("应聘岗位 -> ",das)
            if(das.code === 200){
                this.ypgwOptions = das.data;
            }else{
                Object.assign(this.$data, this.$options.data());
            }
        }))
    },
    methods: {
        // 图片回显
        handleAvatarSuccess(uploadFile){
            this.dialogImageUrlShow = true;
            this.menu.imgUrlBase64 = URL.createObjectURL(uploadFile.raw);
        },
        // 上传成功
        handle_success(res){
            this.formData.personalPhoto = res
            console.log("personalPhoto " , this.formData.personalPhoto)
            if (res.data !== null) {
                this.$notify({
                    title: '成功',
                    message: '这是一条成功的提示消息',
                    type: 'success'
                })
            }else{
                this.$notify({
                    title: '失败',
                    message: '这是一条失败的提示消息',
                    type: 'error'
                })
            }
        },
        // 上传图片
        imgins(){
            this.$refs.upload.submit();
        },
        countChange (num) {
            this.edexTable = []
            var index = 0
            var obj = {}
            for (var i = 0; i < num; i++) {
                index++
                obj = {
                    index: index,
                    positionCode: null
                }
                this.edexTable.push(obj)
            }
        },
        saexTr(num){
            this.saexTable = []
            var index = 0
            var obj = {}
            for (var i = 0; i < num; i++) {
                index++
                obj = {
                    index: index,
                    positionCode: null
                }
                this.saexTable.push(obj)
            }
        },
        byval(row){
            this.reclTable.positionName = row.positionName;
            this.reclTable.positionId = row.positionId;
            this.reclTable.jobDemandId = row.id;
        },
        submitForm() {
            this.$refs['vForm'].validate(valid => {
                if (!valid) return
                //TODO: 提交表单
                let arr = {
                    resume:{},
                    resumeClassify:{},
                    educationExperience:[{}],
                    workExperience:[{}]
                }

                if(this.formData.email.indexOf("@qq.com") < 0){
                    this.formData.email = this.formData.email + "@qq.com";
                }
                arr.resume = this.formData;
                arr.resumeClassify = this.reclTable;
                arr.educationExperience = this.edexTable;
                arr.workExperience = this.saexTable;
                console.log("arr --> ", arr)
                // addAtl(arr).then(das =>{
                //     if (das.code === 200) {
                //         this.$notify({
                //             title: '成功',
                //             message: '这是一条成功的提示消息',
                //             type: 'success'
                //         })
                //         this.$router.replace('/per/recruit/atl')
                //     }else{
                //         this.$notify({
                //             title: '错误！',
                //             message: '请检查网络后重试！',
                //             type: 'success'
                //         })
                //     }
                // });
            })
        },
        resetForm() {
            this.$refs['vForm'].resetFields()
        }
    }
}